
public class Translate {
	String translation;
	String link = "";
	public Translate(String txt, String keel){
		if (keel != "et") {
			txt = addPluses(txt);
			String Url2Trans = ("http://translate.google.com/m?hl=en&sl=et&tl="
									+ keel
									+ "&prev=_m&q=" 
									+ txt);
			Connect translate = new Connect(Url2Trans);
			translation = translate.getRawHtml();
			translation = translation.substring(translation.indexOf("class=\"t0\">")+11);
			translation = translation.substring(0, translation.indexOf("</div>"));
		} else {
			translation = txt;
		}
	}
	
	String get(){ return translation;}
	
	String recoverHTML (String link){
		String [] replaceTable = {"&lt;br&gt;", "\n", "&lt;p&gt;", "\n\n", "<br>", "\n", "<p>", "\n\n",  "[link]", link};
		for (int i = 0; i < replaceTable.length; i += 2){
			translation = translation.replace(replaceTable[i], replaceTable[i+1]);
		}
		
		return translation;
	}
	String addPluses (String txt) {
		txt = txt.replace("+", "%2B");
		return txt.replace(" ", "+");
	}
	void out(){ System.out.println (translation); }
	String toStr() { return translation; }
	
}
